<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else
    include 'equip.html';
                
    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
    
    switch($_GET['action']) {
        case 'edit':
    
            switch ($_GET['type']) {
            //update pumps
            case 'pump':                            

            //Date variables
            $day4 = $_POST['day4'];
            $month4 = $_POST['month4'];
            $year4 = $_POST['year4'];

            //Function to make a valid date input
            $date = $year4."-".$month4."-".$day4;


            //SQL Query to update
            $qry = "update pumps set name='".$_POST['name']."',manufacturer='".$_POST['manufacturer']."',gph='".$POST['gph']."',quantity='".$_POST['qty']."',cost='".$_POST['cost']."',date_installed=$date where user_id='". $_SESSION['uid'] ."' and id='".$_GET['id']."'";

            break;
           
            //update reactor
            case 'reactor':                

            //Date variables
            $day3 = $_POST['day3'];
            $month3 = $_POST['month3'];
            $year3 = $_POST['year3'];
            
            $day2 = $_POST['day2'];
            $month2 = $_POST['month2'];
            $year2 = $_POST['year2'];

            //Function to make a valid date input
            $dateinstalled = $year2."-".$month2."-".$day2;
            $mediachange = $year3."-".$month3."-".$day3;

            //SQL Query to add tank info
            $qry = "update reactors set media='".$_POST['media']."',reactortype='".$_POST['reactortype']."',date_installed=$dateinstalled,media_changed=$mediachange,manufacturer='".$_POST['manufacturer']."'  where where user_id='". $_SESSION['uid']."' and id='".$_GET['id']."'";
            
            break;
            
            //update skimmer
            case 'skimmer':                

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Function to make a valid date input
            $datepurchased = $year."-".$month."-".$day;

            //SQL Query to add tank info
            $qry = "update skimmer set name='".$_POST['name']."',type='".$_POST['type']."',manufacturer='".$_POST['manufacturer']."',gph='".$_POST['gph']."',cost='".$_POST['cost']."',date_installed='$datepurchased' where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."'";
            
            break; 
           }
           
        break;
      }
        
        //Execute Insert command
        if (!mysql_query($qry,$con))
            {
              die('Error: ' . mysql_error());
            }
            echo "Equipment updated!"; 
            echo $qry;
               
    //Close SQL input
    mysql_close($con);

?>
